package com.winter.iterator;

import org.junit.Test;

import java.util.*;

/**
 * @program: Collection
 * @description: iterator迭代器
 * @author: Mr.Liang
 * @create: 2018-01-02 14:23
 **/
public class ListIterator {
    @Test
    public void iterator() {
        /**
         * @Description: collection集合，iterator迭代器
         * @Param: []
         * @return: void
         * @Author: Mr.Wang
         * @Date: 13:59 2018/1/2
         */
        ArrayList<Object> list = new ArrayList<Object>();
        Iterator<Object> iterator = list.iterator();//得到一个迭代子
        while (iterator.hasNext()){
            Object next = iterator.next();//得到下一个元素
            System.out.println(next);
        }
    }
    @Test
    public void enumeration(){
        /**
         * @Description: 枚举迭代器
         * @Param: []
         * @return: void
         * @Author: Mr.Wang
         * @Date: 11:31 2018/1/2
         */
        Enumeration<Object> objectEnumeration = new StringTokenizer("A-B-C","-");
        while (objectEnumeration.hasMoreElements()){
            System.out.println(objectEnumeration.nextElement());
        }
    }
}
